package com.wd.cloud.applet.controller.manage;

import com.wd.cloud.applet.common.Response;
import com.wd.cloud.applet.common.exception.CustomException;
import com.wd.cloud.applet.config.CustomListResultConfig;
import com.wd.cloud.applet.entity.bo.SysUsersInfoBO.SysUsersInfoListBO;
import com.wd.cloud.applet.entity.bo.SysUsersInfoBO.SysUsersInfoLoginBO;
import com.wd.cloud.applet.entity.bo.SysUsersInfoBO.SysUsersInfoSaveBO;
import com.wd.cloud.applet.entity.commons.RequestPrimaryKeyModel;
import com.wd.cloud.applet.entity.vo.SysUsersInfoVO.SysUsersInfoListVO;
import com.wd.cloud.applet.entity.vo.SysUsersInfoVO.SysUsersInfoKeyVO;
import com.wd.cloud.applet.entity.vo.SysUsersInfoVO.SysUsersInfoLoginVO;
import com.wd.cloud.applet.service.ISysUsersInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 用户表控制器
 * Created on 2023年04月23日
 * @author  <a href="mailto: 987707681@qq.com">hjx</a>
 * @version 1.0
 * Copyright (c) 2023年 代码生成器
 */
@Api(tags = "用户表控制器")
@RestController
@RequestMapping("api/manage/sysUsersInfo")
public class SysUsersInfoController {
    @Resource
    private ISysUsersInfoService sysUsersInfoService;
    /**
     * 获取用户信息
     *
     * @param
     * @return
     */
    @ApiOperation(value = "获取用户信息")
    @GetMapping("/userInfo")
    public Response<SysUsersInfoKeyVO> userInfo() {
        SysUsersInfoKeyVO model = sysUsersInfoService.userInfo();
        return Response.ok(model);
    }
    /**
     * 根据ID获取实体数据
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "用户登录")
    @PostMapping("/login")
    public Response<SysUsersInfoLoginVO> login(@RequestBody SysUsersInfoLoginBO dto) {
        SysUsersInfoLoginVO model = sysUsersInfoService.login(dto);
        return Response.ok(model);
    }
    /**
     * 退出登录
     *
     * @param
     * @return
     */
    @ApiOperation(value = "退出登录")
    @PostMapping("/logout")
    public Response logout() {
        sysUsersInfoService.logout();
        return Response.ok();
    }

    /**
     * 新增/编辑
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "新增/编辑")
    @PostMapping("/save")
    public Response save(@RequestBody SysUsersInfoSaveBO dto) {
        if (sysUsersInfoService.save(dto)>0) {
            return Response.ok();
        } else {
            throw new CustomException("操作失败", 101);
        }
    }
    /**
     * 删除操作
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "删除操作")
    @PostMapping("/delByIdentify")
    public Response delByIdentify(@RequestBody RequestPrimaryKeyModel dto) {
        if (sysUsersInfoService.deleteByPrimaryKey(dto) > 0) {
            return Response.ok("删除成功");
        } else {
            throw new CustomException("操作失败", 101);
        }
    }
    /**
     * 获取分页列表数据
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "获取分页列表数据")
    @PostMapping("/getListPage")
    public Response<CustomListResultConfig<SysUsersInfoListVO>> getListPage(@RequestBody
                                                                                    SysUsersInfoListBO params) {
        CustomListResultConfig<SysUsersInfoListVO> selectByPageList = sysUsersInfoService.selectByPageList(params);
        return Response.ok(selectByPageList);
    }
}
